package com.kuang.controller;

import com.kuang.pojo.AstControllerRegister;
import com.kuang.pojo.AstImportControllerLog;
import com.kuang.service.asset.AstControllerRegisterService;
import com.kuang.service.asset.AstImportControllerLogService;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
@Log4j
public class AstImportControllerLogController {

    @Resource
    AstImportControllerLogService astImportControllerLogService;

    /**
     *接口日志 全部数据
     * @param model
     * @return
     */
    @RequestMapping("getAstImportControllerLogs")
    public String getAstImportControllerLogs(Model model){
        List<AstImportControllerLog> astImportControllerLogs = astImportControllerLogService.selectAll();
        model.addAttribute("datas",astImportControllerLogs);
        model.addAttribute("controller_code","");
        model.addAttribute("controller_name","");
        return "mqtt/ast_import_controller_log_list";
    }

    /**
     * 接口日志 全部数据 通过条件
     * @param model
     * @return
     */
    @PostMapping("getAstImportControllerLogByExample")
    public String getAstImportControllerLogsByExample(AstImportControllerLog astImportControllerLog,Model model){
        List<AstImportControllerLog> astImportControllerLogs = astImportControllerLogService.selectAllByExample(astImportControllerLog);
        model.addAttribute("datas",astImportControllerLogs);
        model.addAttribute("controller_code",astImportControllerLog.getController_code());
        model.addAttribute("controller_name",astImportControllerLog.getController_name());
        return "mqtt/ast_import_controller_log_list";
    }

    /**
     * 获取设备信息通过id
     * @param model
     * @return
     */
    @RequestMapping("getAstImportControllerLogById/{id}")
    public String getAstImportControllerLogById(@PathVariable("id") String id, Model model){
        AstImportControllerLog astImportControllerLog = new AstImportControllerLog();
        astImportControllerLog.setAst_import_controller_log_id(id);
        List<AstImportControllerLog> astImportControllerLogs = astImportControllerLogService.selectAllByExample(astImportControllerLog);
        model.addAttribute("data",astImportControllerLogs.get(0));
        return "mqtt/ast_import_controller_log_from";
    }

}
